#ifndef __COMMON_H__
#define __COMMON_H__

#include<iostream>
#include<string>
#include<stdlib.h>
#include<unistd.h>
#include<cstring>
#include<cstdlib>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<sys/stat.h>
#include<fcntl.h>
using namespace std;

const int size = 1024;
const string pathname = "/home/Aries";
const string stupath = "./students.txt";
const int proj_id = 29999;
const int linesize = 64;

key_t GetKey()
{
    key_t k = ftok(pathname.c_str(), proj_id);
    if(k < 0) exit(1);

    return k;
}

int GetShmHelper(int flag)
{
    key_t k = GetKey();
    int shmid = shmget(k, size, flag);
    if(shmid < 0) exit(2);

    return shmid;
}

int CreateShm()
{
    return GetShmHelper(IPC_CREAT | IPC_EXCL | 0666);
}

int GetShm()
{
    return GetShmHelper(IPC_CREAT);
}

typedef struct Student 
{
    string name;
    string gender;
    int age;
    string classinfo;
}Student;


#endif